package org.onion.pattern.event.spring.consumer;

import org.onion.pattern.event.consumer.EventConsumeHandler;
import org.onion.pattern.event.consumer.ExternalEventInfo;
import org.onion.pattern.event.exception.EventConsumeException;
import org.springframework.context.ApplicationContext;


/**
 * 转成spring 事件
 */
public abstract class PublishSpringApplicationEventHandler implements EventConsumeHandler {

    protected ApplicationContext applicationContext;


    @Override
    public void handle(ExternalEventInfo eventInfo, Object metadata) throws EventConsumeException {
        Object applicationEvent = this.buildPublishEvent(eventInfo, metadata);
        this.applicationContext.publishEvent(applicationEvent);
    }

    protected abstract Object buildPublishEvent(ExternalEventInfo eventInfo, Object metadata);

}
